import com.adobe.cairngorm.control.CairngormEventDispatcher;

import mx.events.CloseEvent;
import mx.managers.PopUpManager;

import net.optix.ip.events.AddMatterEvent;
import net.optix.ip.model.ModelLocator;
import net.optix.ip.vo.MatterVO;

import views.ViewInstance;
            
[Bindable]
public var model:ModelLocator	=	ModelLocator.getInstance(); 
  
public function init():void
{
 	model.bSubmit	=	true;
	model.result	=	"";
}
  			
private function titleWindow_close(evt:CloseEvent):void { 
 	model.result	=	"";
 	model.bSubmit	=	true;
	PopUpManager.removePopUp(this); 
}

private function newMatter():void
{
	try
	{
		var result:Boolean	=	true;
		
		var clientID:int	=	matters.selectedItem.clientID;
		var clientEmail:String	=	matters.selectedItem.email;
		
		var firmID		=	model.firm.firmID;
		var message		=	message.text;
		
		var title:String=	titleName.text;
		
		if(title == "")
		{
			result	=	false;
		}
		
		if(clientID == 0)
		{
			result	=	false;
			ViewInstance.showMessage("","Select one client");
		}
		
		var vo:MatterVO	=	new MatterVO();
		vo.firmID		=	firmID;
		vo.clientID		=	clientID;
		vo.clientEmail	=	clientEmail;
		vo.title		=	title;
			
		var type:int	=	-1;
		switch(radioGroup.selectedValue)
		{
			case "Patent":
				type	= 0;
				break;
			case "Trademark":
				type	= 1;
				break;
			case "Copyright":
				type	= 2;
				break;
		}
			
		vo.type	= type;
		vo.message	= message;
		var event:AddMatterEvent	= new AddMatterEvent(vo);
		com.adobe.cairngorm.control.CairngormEventDispatcher.getInstance().dispatchEvent(event);
		
	}
	catch(error:Error)
	{
		trace(error.getStackTrace());
		ViewInstance.showMessage("","Program error");
	}
	
	//ViewInstance.showMessage("","This will come soon");
}